<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "tb_friend".
 *
 * @property integer $id
 * @property string $name
 * @property string $sex
 * @property string $bir
 * @property string $city
 * @property string $address
 * @property string $postcode
 * @property string $email
 * @property string $tel
 * @property string $handset
 * @property string $qq
 * @property string $username
 * @property integer $u_id
 */
class TbFriend extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tb_friend';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['bir'], 'safe'],
            [['u_id'], 'integer'],
            [['name', 'city', 'email'], 'string', 'max' => 50],
            [['sex'], 'string', 'max' => 10],
            [['address'], 'string', 'max' => 100],
            [['postcode'], 'string', 'max' => 6],
            [['tel', 'handset', 'qq', 'username'], 'string', 'max' => 20],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'sex' => 'Sex',
            'bir' => 'Bir',
            'city' => 'City',
            'address' => 'Address',
            'postcode' => 'Postcode',
            'email' => 'Email',
            'tel' => 'Tel',
            'handset' => 'Handset',
            'qq' => 'Qq',
            'username' => 'Username',
            'u_id' => 'U ID',
        ];
    }

    /**
     * 根据姓名查询好友
     * @param $username
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function selectName($username){
        return $sql=self::find()->where(['name'=>$username])->asArray()->one();
    }

    /**
     * 根据U_id查找好友
     * @param $u_id
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function selectU_ID($u_id){
        return $sql=self::find()->where(['u_id'=>$u_id])->asArray()->all();
    }
}